Executes a for loop in which iterations may run in parallel.
Namespace:
System.Threading.Tasks
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Shared Function For(Of TLocal) ( _
fromInclusive As Integer, _
toExclusive As Integer, _
localInit As Func(Of TLocal), _
body As Func(Of Integer, ParallelLoopState, TLocal, TLocal), _
localFinally As Action(Of TLocal) _
) As ParallelLoopResult |
C# |
---|
public static ParallelLoopResult For<TLocal>(
int fromInclusive,
int toExclusive,
Func<TLocal> localInit,
Func<int, ParallelLoopState, TLocal, TLocal> body,
Action<TLocal> localFinally
)
|
Parameters
- fromInclusive
- Type: System..::.Int32
The start index, inclusive.
- toExclusive
- Type: System..::.Int32
The end index, exclusive.
- localInit
- Type: System..::.Func<(Of <(TLocal>)>)
The function delegate that returns the initial state of the local data
for each thread.
- body
- Type: System..::.Func<(Of <(Int32, ParallelLoopState, TLocal, TLocal>)>)
The delegate that is invoked once per iteration.
- localFinally
- Type: System..::.Action<(Of <(TLocal>)>)
The delegate that performs a final action on the local state of each
thread.
Type Parameters
- TLocal
- The type of the thread-local data.
Return Value
A
ParallelLoopResult structure
that contains information on what portion of the loop completed.
Remarks
Exceptions
Exception | Condition |
---|
System..::.ArgumentNullException | The exception that is thrown when the body
argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the
localInit argument is null. |
System..::.ArgumentNullException | The exception that is thrown when the
localFinally argument is null. |
System..::.AggregateException | The exception that is thrown to contain an exception
thrown from one of the specified delegates. |
See Also